package se.chalmers.tda366.crumble;

import java.awt.Point;

import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;

import se.chalmers.tda366.crumble.ctrl.MainController;
import se.chalmers.tda366.crumble.gui.CrumbleFrame;



/**
 * The application entry point
 * @author hajo
 *
 */
public class Main {

	private static ImageIcon logo = new ImageIcon(Main.class.getResource("images/Crumble_icon64.png"));
	
	public static void main(String[] args) {
		// This is the way to construct the GUI
		// (in the event thread)
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				MainController mainController = MainController.getInstance();
				CrumbleFrame mf = new CrumbleFrame();
				mainController.setMainFrame(mf);
				mainController.setCategoryTabs(mf.getCategoryTabbedPane());
				mainController.setFrontPagePanel(mf.getFrontpagePanel());
				mainController.setStatusLabel(mf.getStatusLabel());
				mainController.updateCategoryTabs();
				mainController.updateAll();
				mainController.initDownload();
				Point newPos = mainController.loadMainFramePosition();
				if(newPos != null)
				{
					mf.setLocation(newPos);
				}
				else
				{
					mf.setLocationRelativeTo(null);
				}
				mf.setVisible(true);
				mf.setPreferredSize(mainController.loadMainFrameDimension());
				mf.setSize(mf.getPreferredSize());
		        mf.setIconImage(logo.getImage());
			}
		});
	}
}
